package com.stock.stockprediction.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stock.stockprediction.entity.Stock;
import com.stock.stockprediction.entity.StockMongo;
import com.stock.stockprediction.entity.vo.StockMonthVo;
import com.stock.stockprediction.entity.vo.StockVo;
import com.stock.stockprediction.service.StockService;
import com.stock.stockprediction.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xtt
 * @since 2022-06-03
 */
@Slf4j
@CrossOrigin
@Api(description = "股票数据控制器")
@RestController
@RequestMapping("/stockprediction/stock")
public class StockController {
    @Autowired
    private StockService stockService;



    @ApiOperation("查询所有股票数据")
    @PostMapping("/getAll/{page}/{limit}")
    public R getAll(@PathVariable("page") Long page,
                    @PathVariable("limit") Long limit,
                    @RequestBody(required = false) StockVo stock)  {
//        List<Stock> list = stockService.list(null);
//        return R.ok().data("data",list);
//        System.out.println(stock);
        Page<Stock> stockPage=new Page<Stock>(page,limit);
        Map<String,Object> map = stockService.getStockList(stockPage,stock);

        return R.ok()
                .data(map);
    }
    //查询所有股票日数据
    @ApiOperation("查询所有股票日数据")
    @PostMapping("/getChartDialyData")
    public R getChartDialyData(@RequestBody(required = false) StockVo stockVo){
        log.info("查询条件:{}",stockVo);
        //获取所有股票日数据并对结果进行封装
       Map<String,Object> map = stockService.getAllDialyData(stockVo);
        return R.ok()
                .data(map);
    }


    @ApiOperation("查询所有月数据")
    @PostMapping("/getChartData")
    public R getChartData(@RequestBody(required = false) StockVo stockVo){
        //查询所有月数据
        Map<String,Object>map = stockService.getStockListByMonth(stockVo);

        return R.ok()
                .data(map);
    }

    @ApiOperation("查询所有月数据(带分页)")
    @PostMapping("/getAllMonthData/{page}/{limit}")
    public R getAllMonthData(@PathVariable("page") Long page,
                             @PathVariable("limit") Long limit){
        Map<String,Object> map=stockService.getAllMonthData(page,limit);

        return R.ok()
                .data(map);
    }
    @ApiOperation("从mongodb中获取预测数据和真实数据")
    @PostMapping("/getPredictData/{label}")
    public R getPredictData(@PathVariable("label") String label){
        StockMongo mongo = stockService.findMongo(label);
        return R.ok()
                .data("mongo",mongo);
    }

}

